package com.working.libbase.base

import android.graphics.drawable.ColorDrawable
import android.os.Bundle
import android.os.PersistableBundle
import android.view.MenuItem
import androidx.annotation.LayoutRes
import androidx.appcompat.app.AppCompatActivity
import androidx.databinding.DataBindingUtil
import androidx.databinding.ViewDataBinding
import com.working.libcommon.exts.statusBarColor
import com.working.libcommon.util.LogUtils

abstract class BaseActivity : AppCompatActivity() {

    private val className = this.javaClass.simpleName

    protected inline fun <reified T : ViewDataBinding> binding(
        @LayoutRes resId: Int
    ) = lazy<T> { DataBindingUtil.setContentView(this, resId) }

    override fun onOptionsItemSelected(item: MenuItem): Boolean {
        if (item.itemId == android.R.id.home) {
            onBackPressed()
            return true
        }
        return super.onOptionsItemSelected(item)
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        LogUtils.e("$className onCreate")
    }

    override fun onStart() {
        super.onStart()
        LogUtils.e("$className onStart")
    }

    override fun onResume() {
        super.onResume()
        LogUtils.e("$className onResume")
    }

    override fun onPause() {
        super.onPause()
        LogUtils.e("$className onPause")
    }

    override fun onStop() {
        super.onStop()
        LogUtils.e("$className onStop")
    }

    override fun onDestroy() {
        super.onDestroy()
        LogUtils.e("$className onDestroy")
    }

    override fun onRestoreInstanceState(savedInstanceState: Bundle) {
        super.onRestoreInstanceState(savedInstanceState)
        LogUtils.e("$className onRestoreInstanceState")
    }

    override fun onSaveInstanceState(outState: Bundle, outPersistentState: PersistableBundle) {
        super.onSaveInstanceState(outState, outPersistentState)
        LogUtils.e("$className onRestoreInstanceState")
    }

    override fun onRestart() {
        super.onRestart()
        LogUtils.e("$className onRestart")
    }

    fun immerseColor(colorInt: Int) {
        supportActionBar?.setBackgroundDrawable(
            ColorDrawable(
                colorInt
            )
        )
        statusBarColor(colorInt)
    }

}